import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testcase = "dbshop-006删除取消订单"

# 登录后台
firefox = openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)

# 1.点击销售管理订单管理界面。
DBshopEnterMenu2(firefox,"销售管理","订单管理")
time.sleep(5)
s=firefox.find_element_by_xpath("//body").text
l="订单数\："
r="\)"
num1=reGetString(s,l,r)
print(num1)

# 2.在订单状态点击已取消一栏，点击“搜索”按钮一款，勾选之后，选择删除，点击提交操作。
firefox.find_element_by_id('order_state').click()
firefox.find_element_by_xpath('//option[@value="0"]').click()
firefox.find_element_by_xpath('//i[@class="icon-search icon-white"]').click()
time.sleep(5)
# 勾选
firefox.find_element_by_xpath('//input[@name="order_id[]"]').click()
firefox.find_element_by_id("allEdit").click()
firefox.find_element_by_xpath('//option[@value="del"]').click()
# 提交操作
firefox.find_element_by_xpath('//button[contains(text(),"提交操作")]').click()
time.sleep(5)
firefox.switch_to.alert.accept()# 3.删除成功
time.sleep(10)


#删除前的订单数=删除后的订单数+1
s=firefox.find_element_by_xpath("//body").text
num2=reGetString(s,l,r)
print(num2)
if int(num1)==int(num2)+1:
    writeLog("%s 测试通过" % (testcase))
else:
    writeLog("%s 测试失败" % (testcase))
    getPhoto(firefox)
# firefox.quit()